import re

print(re.match(r'^\d{3}\-\d{3,8}$', '010-12345'))  # 匹配
print(re.match(r'[a-zA-Z\-]+\d{1,5}', 'aadas$dasd-1'))
print(re.split(r'[\s\,]+', 'a,b, c d'))  # 字符串分割
m1 = re.match(r'([a-zA-Z0-9\-\$]*)([a-zA-Z\-]+\d{1,5})', 'aadas$dasd-1')
# 非贪婪模式 "?"
m2 = re.match(r'([a-zA-Z0-9\-\$]*?)([a-zA-Z\-]+\d{1,5})', 'aadas$dasd-1')
print(m1.group(2))
print(m2.group(2))
# 提前编译正则表达式
m_complie = re.compile(r'([a-zA-Z0-9\-\$]*?)([a-zA-Z\-]+\d{1,5})')
print(m_complie.match('aadas$dasd-1').groups())

# 练习
test1 = re.compile(r'^[a-zA-Z0-9][a-zA-Z0-9\.]*\@[a-zA-Z0-9]+\.[a-z]{1,5}')
print(test1.match("bill.gates@microsoft.com"))
test2 = re.compile(r'^\<([a-zA-Z0-9]+)\s*([a-zA-Z0-9]+)\>\s*[a-zA-Z0-9\.]'
                   + r'+\@[a-zA-Z0-9]+\.[a-z]{1,5}')
print(test2.match("<Bill Gates> bill.gates@microsoft.com").groups())
